package com.ebupt.migu.fineoperationactivitymonitor.common.util;

import org.apache.commons.lang3.StringUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * @program: graphic
 * @description:
 * @author: zhanggk
 * @create: 2018-10-12 14:36
 **/
@Slf4j
public class DefaultVal {

    /**
     * String 转换 int
     * 
     * @param str string
     * @param defaultVal 默认值，str不是int类型，返回默认值
     * @return int
     */
    public static int strToInt(String str, int defaultVal) {
        int val = defaultVal;
        if (!StringUtils.isBlank(str)) {
            try {
                val = Integer.parseInt(str);
            } catch (NumberFormatException e) {
                log.error("add message err", e);
            }
        }
        return val;
    }

}